import MeetingHeader from '@/components/MeetingHeader'
import WebRecommendBrowser from '@/components/WebRecommendBrowser'
import useInit from '@/hooks/useInit'
import { getUrlParams } from '@/utils'
import { Button, Tab } from '@kedacom/react-next'
import dayjs from '@/plugins/dayjs'
import React, { useState } from 'react'
import MccMeetingLog from './MccMeetingLog'
import ReservationLog from './ReservationLog'
import SaveDateModal from './SaveDateModal'
import { StyledWrap } from './style'
import { t } from 'i18next'

export default function App() {
	const [tab, setTab] = useState(getUrlParams('tabFlag') === 'mccMeetingLog' ? 1 : 0)
	const [open, setOpen] = useState(false)
	const [minDate, setMinDate] = useState('')
	useInit()
	return (
		<>
			<WebRecommendBrowser />
			<MeetingHeader tabIndex={7} />
			<StyledWrap className="syslog">
				<div className="top-nav">
					<Tab
						value={tab}
						type="button"
						data={[
							{ label: t('综合日志'), value: 0 },
							{ label: t('会场管理日志'), value: 1 },
						]}
						onChange={(e, val) => setTab(val)}
					/>
					<Button onClick={() => setOpen(true)}>{t('保存期限设置')}</Button>
				</div>
				{tab === 0 && <ReservationLog minDate={minDate} />}
				{tab === 1 && <MccMeetingLog minDate={minDate} />}
				<SaveDateModal
					open={open}
					setOpen={setOpen}
					setMinDate={(val) => {
						setMinDate(dayjs().subtract(val, 'day').format('YYYY-MM-DD'))
					}}
				/>
			</StyledWrap>
		</>
	)
}
